package dbhandler;

import evthandler.EventMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Casper, Dennis, Jackie, Jakob
 * @version 1.00
 */
public class Prefix{

    private int prefixNo;
    private String prefixName;

    /**
     *
     */
    public Prefix() {
        
    }
    /**
     *
     * @param prefixNo
     */
    public Prefix(int prefixNo) {
        this.prefixNo = prefixNo;
        try {
            ResultSet rs = DbCon.getInstance().executeQuery("SELECT prefixName FROM prefix WHERE prefixNo=" + prefixNo);
            while (rs.next()) {
                prefixName = rs.getString("prefixName");
            }
        } catch (SQLException ex) {
            new EventMessage("SQL error in Prefix", "There was an error performing the sql inquery\n").showException(ex);
        }
    }

    /**
     *
     * @return
     */
    public String getPrefixName() {
        return prefixName;
    }

    /**
     *
     * @return
     */
    public int getPrefixNo() {
        return prefixNo;
    }

    /**
     *
     * @return
     */
    public ArrayList<Prefix> getPrefixes() {
        ArrayList<Prefix> prefixes = new ArrayList<Prefix>();
        ArrayList<Integer> temp = new ArrayList<Integer>();
        try {
            ResultSet rs = DbCon.getInstance().executeQuery("SELECT prefixNo FROM prefix ORDER BY prefixNo");
            while (rs.next()) {
                temp.add(rs.getInt("prefixNo"));
            }
        } catch (SQLException ex) {
            new EventMessage("SQL error in Prefix.getPrefixes()", "There was an error performing the sql inquery\n").showException(ex);
        }
        for (int i = 0; i < temp.size(); i++) {
            prefixes.add(new Prefix(temp.get(i)));
        }
        return prefixes;
    }

    /**
     *
     * @return
     */
    @Override
    public String toString() {
        return prefixName;
    }
}
